/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package test.test;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Geocoder;
import android.os.Bundle;
import android.widget.ImageView;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sio
 */
public class LocalisationActivity extends Activity {

    

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.localisation);
        Intent inter = getIntent();
        String adresse = inter.getStringExtra("adresse");
        /*MapView map;
         map = (MapView) findViewById(R.id.mapView);
         map.setBuiltInZoomControls(true); */

        try {
            String imageFileURL = "http://maps.google.com/maps/api/staticmap?center=" + adresse + "&zoom=15&size=200x200&markers=color:red%7C"+ adresse;

            URL url = new URL(imageFileURL);
            URLConnection conn = url.openConnection();
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream inputStream = httpConn.getInputStream();
                Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                inputStream.close();
                ImageView mapviewz = (ImageView) findViewById(R.id.mapView);
                mapviewz.setImageBitmap(bitmap);
            }

        } catch (MalformedURLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        /*Geocoder geocoder = new Geocoder(new Activity());
             
         try {
         int lat =(int) (geocoder.getFromLocationName(adresse, 1).get(0).getLatitude()*1000000);
         int lng =(int) (geocoder.getFromLocationName(adresse, 1).get(0).getLongitude()*1000000);
         GeoPoint pt=new GeoPoint(lat,lng);
         map.getController().setZoom(15);
         map.getController().setCenter(pt);
         } catch (IOException ex) {
         Logger.getLogger(LocalisationActivity.class.getName()).log(Level.SEVERE, null, ex);
         } */
        /*List<Overlay> mapOverlays=map.getOverlays();
         Marker marker = map.addMarker(new MarkerOptions()
         MyOverlay marker=new MyOverlay(point);
         mapOverlays.add(marker);
         map.invalidate(); */
    }
}
